/**
 * Created by gongxun on 17/3/20.
 */

var PszTableCardTControl = GameBaseItem.extend({
    Image_cardTypeBg : null,
    Image_cardType : null,
    Image_see : null,
    Image_men : null,
    ctor : function() {
        this._super();
        this.loadCocostudio("res/ccs/PszTableCardControl.json");

        this.Image_cardTypeBg = mo.seekWidgetByName(this.ccsNode, "Image_cardTypeBg");
        this.Image_cardType = mo.seekWidgetByName(this.ccsNode, "Image_cardType");
        this.Image_see = mo.seekWidgetByName(this.ccsNode, "Image_see");
        this.Image_men = mo.seekWidgetByName(this.ccsNode, "Image_men");

        this.Image_see.addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.pszTableStatus.sendKanpaiAction();
            }
        }, this);

        this.reset();
    },

    onEnter : function(){
        this._super();

        this.setPosition(mo.pszCardHelper.seatCards[0]);
    },

    reset : function(){
        this.Image_cardTypeBg.setVisible(false);
        this.Image_cardTypeBg.setOpacity(255);
        this.Image_see.setVisible(false);
        this.Image_men.setVisible(false);

        this.Image_cardTypeBg.stopAllActions();
        this.Image_see.stopAllActions();
        this.Image_men.stopAllActions();
    },

    showTishi : function(delayTime){
        var time = 0;
        if (delayTime != undefined){
            time = delayTime;
        }

        this.reset();
        this.Image_men.runAction(cc.sequence(
            cc.delayTime(time),
            cc.show()
        ));
    },

    closeTishi : function(){
        this.Image_see.setVisible(false);
        this.Image_men.setVisible(false);

        this.Image_see.stopAllActions();
        this.Image_men.stopAllActions();
    },

    showMen : function(delayTime){
        mo.gameHelper.loadTextureImage(this.Image_men, "res/ccs/psz/playerInfo/img_menpai.png");
        this.showTishi(delayTime);
    },

    showQipai : function(delayTime){
        mo.gameHelper.loadTextureImage(this.Image_men, "res/ccs/psz/playerInfo/img_qipai.png");
        this.showTishi(delayTime);
    },

    showBipaiShu : function(delayTime){
        mo.gameHelper.loadTextureImage(this.Image_men, "res/ccs/psz/playerInfo/img_bipaishu.png");
        this.showTishi(delayTime);
    },

    showSee : function(delayTime){
        var time = 0;
        if (delayTime != undefined){
            time = delayTime;
        }

        this.reset();
        this.Image_see.runAction(cc.sequence(
            cc.delayTime(time),
            cc.show()
        ));
    },

    showCardType : function(cardType, delayTime){
        var time = 0;
        if (delayTime != undefined){
            time = delayTime;
        }

        mo.gameHelper.loadTextureImage(this.Image_cardType, "res/ccs/psz/playerInfo/type_" + cardType + ".png");
        if (time == 0){
            this.Image_cardTypeBg.setVisible(true);
        }else{
            this.Image_cardTypeBg.setPosition(cc.p(0, -35));
            this.Image_cardTypeBg.setOpacity(0);
            this.Image_cardTypeBg.runAction(cc.sequence(
                cc.delayTime(time),
                cc.show(),
                cc.spawn(
                    cc.moveTo(0.2, cc.p(0, 0)),
                    cc.fadeIn(0.2)
                )
            ))
        }
    }
});